package array;

import java.util.HashSet;

public class L169 {
    public int majorityElement(int[] nums) {
        int sum=0,major=0;
        HashSet<Integer> integers = new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            integers.add(nums[i]);
        }
        for (Integer item : integers){
            int current=0,currentmajor=0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i]==item){
                   current+=1;
                   currentmajor=nums[i];
                }
            } if (current>sum){
                sum=current;
                major=currentmajor;
            }
        }
        return major;


    }
}
